//
//  BlackViewController.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/3/24.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "BlackViewController.h"
#import "BlackTableViewCell.h"
#import "BlackList.h"
#import "BlackLogic.h"
@interface BlackViewController ()<QMUITableViewDelegate,QMUITableViewDataSource,BlackDelegate>
@property(nonatomic, strong) BlackLogic *logic;

@end

@implementation BlackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    _logic = [[BlackLogic alloc] init];
    _logic.delegagte = self;
    self.title = ASLocalizedString(@"黑名单");
    [self loadData];
    
}
-(void)createUI
{
    NSString *cellid = NSStringFromClass([BlackTableViewCell class]);

    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerNib:[UINib nibWithNibName:cellid bundle:nil] forCellReuseIdentifier:cellid];
    [self.view addSubview:self.tableView];
    
    //设置约束
    [self setLayout];
}

-(void)setLayout
{
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view);
        make.top.equalTo(self.view).offset(5);
        make.bottom.equalTo(self.view.mas_bottom).offset(5);
    }];
}
- (void)loadData {
    [_logic loadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark -tableview

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _logic.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 54;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BlackTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BlackTableViewCell class])];
    BlackList *model = _logic.dataArray[indexPath.row];
    [cell setModel:model];
    
    kWeakSelf(self);
    
    cell.UnBackSuccess = ^{
        [weakself.logic loadData];
    };
    
    return cell;
}



#pragma mark ————— 下拉刷新 —————
-(void)headerRereshing{
    _logic.page = 1;
    [_logic loadData];
    
}

#pragma mark ————— 上拉刷新 —————
-(void)footerRereshing{
    _logic.page+=1;
    [_logic loadData];
}

#pragma mark ————— 数据拉取完成 渲染页面 —————
-(void)requestDataCompleted{
   
    [self.tableView.mj_footer endRefreshing];
    [self.tableView.mj_header endRefreshing];
    
    [UIView performWithoutAnimation:^{
        [self.tableView reloadData];
    }];
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}



@end
